home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 2 / CU Amiga Magazine's Super CD-ROM 02 (1996)(EMAP Images)(GB)[!][issue 1996-04].iso / magazine / amiga_e / modulesmc1 / qstringf.e < prev    next >
Text File  |  1994-11-09  |  3KB  |  170 lines

  1. OPT MODULE
  2. EXPORT PROC stringf(str,format,listptr=NIL:PTR TO LONG)
  3.    MOVEA.L str,A0
  4.    MOVE.L A0,A6
  5.    MOVEA.L format,A1
  6.    MOVEA.L listptr,A2
  7. nxt:
  8.    MOVE.B (A1)+,(A0)+
  9.    BEQ.S  done
  10.    CMPI.B  #"%",-1(A0)
  11.    BNE.S nxt
  12.    MOVE.B (A1)+,(A0)+
  13.    CMPI.B  #"l",-1(A1)
  14.    BEQ.S gotl
  15.    CMPI.B  #"s",-1(A1)
  16.    BNE.S nxt
  17.    SUBQ.W #2,A0      /* eat the %s    */
  18.    MOVEA.L (A2)+,A3     /* must be a string pointer  */
  19. dcopy:
  20.    MOVE.B  (A3)+,(A0)+    /* copy byte  */
  21.    BNE.S dcopy
  22.    SUBQ.W  #1,A0      /* write over 0  */
  23.    BRA.S  nxt
  24.  
  25. done:
  26.    SUBA.L A6,A0
  27.    SUBQ.L #1,A0     /* length  */
  28.    EXG A6,A0        /* A0 points to str, A6 to length  */
  29.    CMPA.W -4(A0),A6      /* compare with maxlength  */
  30.    BHI.S toolong
  31.    MOVE.W A6,-2(A0)      /* equivalent to SetStr()  */
  32. toolong:
  33.    MOVE.L A6,D1
  34.    MOVE.L A0,D0
  35.    BRA endstringf
  36.  
  37. gotl:
  38.    MOVE.B (A1)+,D0
  39.    MOVE.B D0,(A0)+
  40.    CMPI.B #"d",D0
  41.    BEQ.S gotdec
  42.    CMPI.B #"x",D0
  43.    BEQ gothex
  44.    CMPI.B #"c",D0
  45.    BEQ.S gotchar
  46.    CMPI.B #"b",D0
  47.    BNE.S nxt
  48.    SUBQ.W #3,A0    /* eat %lb  */ /* bin routine starts here  */
  49.    MOVE.L (A2)+,D0
  50.    BEQ.S binzero
  51.    MOVEQ #31,D1
  52. next0:
  53.    BTST  D1,D0
  54.    DBNE D1,next0
  55. nextbit:
  56.    BTST D1,D0
  57.    BEQ.S bit0
  58.    MOVE.B #"1",(A0)+
  59.    BRA.S bit1
  60. bit0:
  61.    MOVE.B #"0",(A0)+
  62. bit1:
  63.    DBRA D1,nextbit
  64.    BRA nxt
  65.  
  66. binzero:
  67.    MOVE.B #"0",(A0)+
  68.    BRA nxt
  69.  
  70. gotchar:
  71.    SUBQ.W #3,A0
  72.    MOVE.L (A2)+,D0
  73.    MOVE.B D0,(A0)+
  74.    BRA nxt
  75.  
  76. gotdec:
  77.    SUBQ.W #3,A0
  78.    MOVE.L (A2)+,D0
  79.    SUBA.W  #14,A7
  80.    MOVEA.L A7,A3
  81.    MOVE.L D0,D2
  82.    BGE.S repeatbig
  83.    NEG.L D0
  84. repeatbig:
  85.    CMPI.L #655359,D0
  86.    BHI.S  bignumber
  87. repeat:
  88.    MOVEQ  #10,D1
  89.    CMP.L D1,D0
  90.    BHI.S norm
  91.    BEQ.S is1
  92.    MOVE.L D0,D1
  93.    MOVEQ  #0,D0
  94.    BRA.S cont
  95.  
  96. norm:
  97.    DIVU  D1,D0
  98.    SWAP  D0
  99.    CLR.L D1
  100.    MOVE.W D0,D1
  101.    CLR.W D0
  102.    SWAP  D0
  103. cont:
  104.    ADDI.B #"0",D1
  105.    MOVE.B D1,(A3)+
  106.    TST.L D0
  107.    BGT.S repeat
  108.    TST.L D2
  109.    BGE.S notneg
  110.    MOVE.B #"-",(A3)+
  111. notneg:
  112.    MOVE.B  -(A3),(A0)+
  113.    CMPA.L  A3,A7
  114.    BLT.S notneg
  115.    ADDA.W #14,A7
  116.    BRA nxt
  117.  
  118. is1:
  119.    MOVEQ #1,D0
  120.    MOVEQ #0,D1
  121.    BRA.S cont
  122.  
  123. bignumber:
  124.    MOVEM.L D2/D3,-(A7)
  125.    MOVEQ #10,D1
  126.    MOVE.L D0,D2
  127.    CLR.W D2
  128.    SWAP D2
  129.    DIVU D1,D2
  130.    CLR.L D3
  131.    MOVE.W D2,D3
  132.    SWAP D3
  133.    MOVE.W D0,D2
  134.    DIVU D1,D2
  135.    MOVE.L D2,D1
  136.    CLR.W D1
  137.    SWAP D1
  138.    CLR.L D0
  139.    MOVE.W D2,D0
  140.    ADD.L D3,D0
  141.    ADD.B #"0",D1
  142.    MOVE.B D1,(A3)+
  143.    MOVEM.L (A7)+,D2/D3
  144.    BRA repeatbig
  145.  
  146. gothex:
  147.    MOVE.L (A2)+,D0
  148.    SUBQ.W #3,A0
  149.    MOVEA.L A7,A3
  150.    SUBA.W  #14,A3
  151.    MOVEQ #-1,D2
  152. nextltr:
  153.    MOVE.B D0,D1
  154.    ANDI.B #$0F,D1
  155.    ADDI.B #48,D1
  156.    CMPI.B #57,D1
  157.    BLE.S around
  158.    ADDQ.B #7,D1
  159. around:
  160.    MOVE.B D1,(A3)+
  161.    LSR.L #4,D0
  162.    DBEQ D2,nextltr
  163.    NOT.L D2
  164. loadstr:
  165.    MOVE.B -(A3),(A0)+    /* reverse buffer  */
  166.    DBF D2,loadstr
  167.    BRA nxt
  168. endstringf:
  169. ENDPROC D0
  170.